<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QQ沐编程登录页HTML源码一</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        html {
            height: 100%;
        }
        body {
            height: 100%;
        }
        .container {
            height: 100%;
            background-image: linear-gradient(to right, #fbc2eb, #a6c1ee);
        }
        .login-wrapper {
            background-color: #fff;
            width: 358px;
            height: 588px;
            border-radius: 15px;
            padding: 0 50px;
            position: relative;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }
        .header {
            font-size: 38px;
            font-weight: bold;
            text-align: center;
            line-height: 200px;
        }
        .input-item {
            display: block;
            width: 100%;
            margin-bottom: 20px;
            border: 0;
            padding: 10px;
            border-bottom: 1px solid rgb(128, 125, 125);
            font-size: 15px;
            outline: none;
        }
        .input-item:placeholder {
            text-transform: uppercase;
        }
        .btn {
            text-align: center;
            padding: 10px;
            width: 100%;
            margin-top: 40px;
            background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
            color: #fff;
        }
        .msg {
            text-align: center;
            line-height: 88px;
        }
        a {
            text-decoration-line: none;
            color: #abc1ee;
        }
    </style>
    <script type="text/javascript">

        $(function () {

            $('#login').click(function(event) {
                ajaxT();
            });
        });

        function ajaxT() {
            var url = "http://localhost:80/user/login"

            var userName = $("input[name='username']").val();
            var password = $("input[name='password']").val();

            var postData = {
                userName: userName,
                password: password
            };

            $.ajax({
                    type: "POST",
                    contentType: "application/json", //必须这样写
                    url: url,
                    data: JSON.stringify(postData),
                    datatype: "JSON",
                    success: function (result) {
                        var data = result.data;
                        console.log(JSON.stringify(data));

                        if( Object.keys(data).length !== 0 ){
                            localStorage.setItem("userName", userName);
                            localStorage.setItem(userName, data.Authorization);
                            window.location.href="http://localhost/user/index";
                            // window.open('http://localhost/user/index', '_blank');
                        }else {
                            alert("登录失败，账号或者密码错误！");
                        }
                    },
                    error: function(xhr, textStatus, errorThrown) {
                        // 请求失败时的回调函数
                        alert("系统错误，请联系管理员处理！");
                    }
                }
            );
        }
    </script>
</head>
<body>
<div class="container">
    <div class="login-wrapper">
        <div class="header">登录页面</div>
        <div class="form-wrapper">
            <input type="text" name="username" placeholder="用户名" class="input-item">
            <input type="password" name="password" placeholder="密码" class="input-item">
            <div class="btn" id="login">立即登录</div>
        </div>
        <div class="msg">
            没有账号?
            <a href="https://www.qqmu.com">注册账号</a>
        </div>
    </div>
</div>
</body>
</html>